package com.itheima.functioninterface;

import java.util.Arrays;
import java.util.function.Supplier;

/**
 * <h1>JDK内置Supplier函数接口使用demo1</h1>
 *
 * @author <a href="11n_yd2h5e1jx8@dingtalk.com">叶世铭</a>
 * @since 2024/1/29
 */
public class SupplierDemo1 {
    public static void main(String[] args) {
        getMax(new Supplier<Integer>() {
            @Override
            public Integer get() {
                //1.定义一个数组
                int[] arr = {12,23,34,94,555,60,27,38,99};
                //2.对数组进行排序
                Arrays.sort(arr);
                //3.将最大值返回
                return arr[arr.length - 1];
            }
        });

        getMax(() ->{
            //1.定义一个数组
            int[] arr = {12,23,34,94,555,60,27,38,99};
            //2.对数组进行排序
            Arrays.sort(arr);
            //3.将最大值返回
            return arr[arr.length - 1];

        });
    }

    private static void getMax(Supplier<Integer> supplier) {
        int max = supplier.get();
        System.out.println(max);
    }
}
